home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
batchut
/
ask3.zip
/
ASK3.DOC
< prev
next >
Wrap
Text File
|
1986-12-11
|
14KB
|
388 lines
1. QUICK START
ASK allows you to ask for input from the user in a batch file. The
simplified syntax is
ASK [prompt] [expected Keys]
Prompt is a "quoted" string that will be printed by ASK. Expected
keys is a list of key that you expect from the user. The result
is testable by the "if errorlevel" statement in a batch file. For
example (in a batch file):
echo off
ask "Do you want to run away (y/n)? " yn
if errorlevel 2 goto no
rem *** errorlevel 1 falls thru here. Now run away.
away
:no
When the user runs this batch file, he will get this prompt:
Do you want to run away (y/n)? _
He can press the 'y' or the 'n' key. If he presses the 'y'
key, errorlevel will be set to 1 (because y is the first
character in the expected keys list) and away will be run.
If he presses the 'n' key, errorlevel will be set to 2 and
away will not be run.
This should get you started. There are some other examples
in this document as well as in the file EXAMPLE.BAT (which
you can run).
2. REFERENCE
2.1 Introduction
ASK is a program for you to use in a batch file to ask for one-
key responses from the user. ASK then sets the errorlevel
according to the key pressed. The errorlevel can be tested in a
batch file to branch to different places. This allows you to ask
simple questions like the Yes-or-No type, or to set up a menu-
driven batch file. ASK also accepts options like no echo, time
out, flush type-ahead.
2.2 Syntax
ASK [Options] [Prompt] [Expected Keys]
2.2.1 Prompt
[Prompt] is the question to be displayed. It is a "quoted string"
(double quotes only). You can embbed double quotes in the prompt
by using \" (backslash-quote). If you do not supply [Prompt], ASK
will use the default '? '. If you want an empty prompt, use "".
2.2.2 [Expected Keys]
[Expected Keys] is a string of all the different keys that the
user may press in response to your question. There is no need to
quote this string unless you want to include a space in it.
Another way to include a space is to use '\ ' (blackslash-space).
If the user presses the first key listed in the [Expected Keys],
the errorlevel will be set to 1; if the user presses the second
key in the [Expected Keys], the errorlevel will be set to 2, and
so on. If the user presses a key that is not in the [Expected
Keys], ASK will beep and prompt him again until he gets it right.
You can override this action with the /q option.
If the [Expected Keys] string is not present, the errorlevel will
be set to the character code of the key the user pressed. By
default, lower case letters will be mapped to the upper case
counterpart, i.e. letters always return 65-90. You can disable
this mapping with the /c option.
If there is no [Expected Keys] and the user presses a key that
maps to an extended ASCII, ASK returns 0 (zero). The only way to
match a function key is to list that key in [Expected Keys].
When testing errorlevel, be sure to test for the highest number
first because
if errorlevel 5
means
if errorlevel equal to or greater than 5.
2.3 Options
Options are used to change the behavior of ASK somewhat. The
option letters themselves are not case sensitive so you can use
either upper or lower case.
/F - flush all keys type-ahead before accepting input
/E - no echo. Accept input but do not echo it to the
screen. The cursor is also turned off during input.
/Q - be quiet, don't yell at the user for invalid
response, but return 0 as the errorlevel. This
option is meaningless if there is no [Expected
Keys]. This is normally used when you want to trap
invalid responses and print your own error message
instead of using the built-in one.
/C - make [Expected Keys] case sensitive. This means
letters pressed by the user will only match letters
in the same case in [Expected Keys]. If there is
no [Expected Keys], then UPPER case letters will
return errorlevel 65-90, and lower case letters will
return 97-122.
/Sxxx - timeout after xxx seconds and return errorlevel 255.
xxx can be from 1 to 3 digits and range from 0 to
999.
If you supply 0 (zero) as the timeout value, ASK
will check the keyboard buffer once before it times
out. If there is a key in the buffer (typed ahead),
ASK will read it.
If you do not supply any value, ASK will time out
immediately without even checking type-ahead keys in
the keyboard buffer. You can use ASK this way as an
alternative to DOS' ECHO command. The advantage is
that you can use ASK to print control characters. E.g.
ask/s "\e" > E.TXT will put the escape character in
the file E.TXT.
If more than one timeout option is given, the effect
is cumulative. Accuracy is from +0 to -1 second. So
if you say s10 it would delay from 9 to 10 seconds.
When ASK times out it will not print a linefeed so
that the next thing you ECHO will appear immediately
after the [prompt]. I usually print *TIMEOUT* so if
a user is watching he will understand why things are
happening even though he didn't press any key.
/Myyy - timeout after yyy minutes and return errorlevel 255.
yyy can be from 1 to 3 digits and range from 0 to
999. See the /S option for other details.
More than one option letter can share a common switch, like
this:
ask /QS50C "Blah Blah? "
ask/qcm5 "Blah Blah? "
ask /c/s9/q "Blah Blah ?"
2.4 Special Characters
Characters that you normally cannot put on a command line (e.g.
carriage return, escape, backspace, ...) can be included in
either [Prompt] or [Expected Keys] using the following
conventions:
\nnn - translates to ASCII nnn where nnn is a 3-digit
decimal number. If this is not followed by another
digit then you don't need to put down all three
digits. If it is followed by a digit, then you have
to put down all three digits (add leading zeros if
necessary).
For example:
ASK "\7HI: " prints a beep and "HI: "
ASK "\0070 HI: " prints a beep and "0 HI:"
ASK "\070 HI: " prints "F HI: "
\e - the escape character. This is equivalent to \27,
\027, or \E.
\\ - the \ (backslash) character itself
\" - the double quote character (without the backslash it
will be interpreted as the beginning or the end of a
quoted string).
\~ - the tilde character itself.
~a - translates to control-a. This works when 'a' is from
ASCII 64 to 95 (which produce ASCII 0 thru 31) or is
a lower case letter.
~(X) - interpret this as a function key. X is the label on
the function key. E.g. ~(f1) refers to the key (F1),
~(ins) refers to the (Ins) key.
The label is not case sensitive, so you can use upper
or lower case. So ~(F1), ~(INS) would also work.
You can use the prefixes S-, C-, and A- with the
labels to denote Shift-, Ctrl-, and Alt- version of
the key, like ~(s-f1), ~(c-f1), and ~(a-f1).
This notation is only recognized in [Expected Keys]
and not in [Prompt], because function keys cannot be
printed.
Here's some examples on using special characters:
ask "How \"are\" you?" - will produce How "are" you?
ask "Hi?\7" - will produce Hi?*BEEP*
ask "Hi?~g" - will also